import fetch from 'node-fetch';

async function testDeleteCategory() {
    console.log('🧪 测试删除文章类别的健壮性判断\n');
    
    const baseUrl = 'http://localhost:8000/api/v1/admin';
    const authToken = 'Bearer admin_token';
    
    try {
        // 1. 测试删除不存在的分类
        console.log('🔥 测试1: 删除不存在的分类（ID: 9999）');
        const response1 = await fetch(`${baseUrl}/category/delete`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': authToken
            },
            body: JSON.stringify({ id: 9999 })
        });
        const result1 = await response1.json();
        console.log(`状态码: ${response1.status}`);
        console.log(`响应: ${JSON.stringify(result1)}\n`);
        
        // 2. 测试删除可能有关联文章的分类（假设ID: 1有关联文章）
        console.log('🔥 测试2: 删除有关联文章的分类（ID: 1）');
        const response2 = await fetch(`${baseUrl}/category/delete`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': authToken
            },
            body: JSON.stringify({ id: 1 })
        });
        const result2 = await response2.json();
        console.log(`状态码: ${response2.status}`);
        console.log(`响应: ${JSON.stringify(result2)}\n`);
        
        // 3. 测试删除没有参数
        console.log('🔥 测试3: 删除时不传ID参数');
        const response3 = await fetch(`${baseUrl}/category/delete`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': authToken
            },
            body: JSON.stringify({})
        });
        const result3 = await response3.json();
        console.log(`状态码: ${response3.status}`);
        console.log(`响应: ${JSON.stringify(result3)}\n`);
        
        console.log('✅ 删除分类健壮性测试完成！');
        
    } catch (error) {
        console.error('测试失败:', error.message);
    }
}

testDeleteCategory();
